﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Savage.DotNetLibrary.ProtocolLibrary
{
    public class SecurityWrapper
    {
        public static string GenerateStrongPassword(int minLength, int maxLength)
        {
            string[] pools = new string[] { "abcdefghjkmnpqrstuvwxyz",
                                           "ABCDEFGHJKLMNPQRSTUVWXYZ",
                                           "23456789",
                                           "!\"£$%^&*()-_=+[{]};:'@#~,<.>/?" };
 
            return GenerateStrongPassword(pools, minLength, maxLength);
        }

        public static string GenerateStrongPassword(string[] pools, int minLength, int maxLength)
        {
            Random rnd = new Random();
            int length = rnd.Next(minLength, maxLength);

            Dictionary<int, string> shortList = new Dictionary<int, string>();
            for (int i = 0; i < pools.Length; i++)
            {
                string temp = String.Empty;
                for (int i2 = 0; i2 < length; i2++)
                {
                    temp += pools[i].Substring(rnd.Next(pools[i].Length), 1);
                }
                shortList.Add(i, temp);
            }
            string password = String.Empty;
            for (int i = 0; i < length; i++)
            {
                password += shortList[rnd.Next(shortList.Count)].Substring(i, 1);
            }

            return password;
        }
    }
}
